public class StockItem implements Comparable<StockItem>{
     private final String name;
     private double price;
     private int quantityStock = 0;

     public StockItem(String name, double price) {
          this.name = name;
          this.price = price;
          this.quantityStock = 0;
     }

     public StockItem(String name, double price, int quantityStock) {
          this.name = name;
          this.price = price;
          this.quantityStock = quantityStock;
     }

     @Override
     public int compareTo(StockItem o) {
          System.out.println("Entering stockItem.compareTo.");
          if (this == o) {
               return 0;
          }
          if (o != null) {
               return this.name .compareTo(o.getName());
          }
          throw new NullPointerException();
     }

     @Override
     public boolean equals(Object obj) {
          System.out.println("Entering StockItem.equals");
          if (obj == this) {
               return true;
          }

          if ((obj.getClass() != this.getClass())) {
               return false;
          }

          String objName = ((StockItem)obj).getName();
          return this.name.equals(objName);
     }

     public String getName() {
          return name;
     }

     public double getPrice() {
          return price;
     }

     public int quantityInStock() {
          return quantityStock;
     }

     public void setPrice(double price) {
          if (price > 0) {
               this.price = price;
          }
     }

     public void adjustStock(int quantity) {
          int newQuantity = this.quantityStock + quantity;
          if (newQuantity >= 0) {
               this.quantityStock = newQuantity;
          }
     }

     @Override
     public int hashCode() {
          return this.name.hashCode() + 31;
     }

     @Override
     public String toString() {
          return this.name + ": price " + this.price;
     }
}


